<template>
    <div>
        <el-container style="height: 700px; border: 5px solid #eee">
            <el-header>
                超市信息管理系统
            </el-header>
            <el-main>
                
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="员工号">
                        <el-input v-model="employee.eid"></el-input>
                    </el-form-item>

                    <el-form-item label="员工密码">
                        <el-input type="password" v-model="employee.epas">
                            <el-button type="primary" slot="append" icon="el-icon-search" v-on:click="log2()">验证码登录</el-button>
                        </el-input>
                    </el-form-item>


                    <el-form-item>
                            <el-button type="primary" v-on:click ="check()">登录</el-button>
                        <br><br>
                    </el-form-item>
                </el-form>
            </el-main>
        </el-container>
    </div>
</template>



<script>
import axios from 'axios';


export default {
    data: function(){
        return{
                employee: {
                eid:'',
                epas:''
             },
            empData: [],/* {
                Eid:'1010',
                Ename:'骆洛',
                EPas:'mysql',
                Elevel:'02',
                EtelPhone:'110',
                ESalary:'5000',
                other:'工作努力'
            } */

        }
        
    },
    methods: {
        check: function(){
            var res = false;
            for(var i=0;i<this.empData.length;i++){
               
                if(this.employee.eid == this.empData[i].eid){
                    res=true;
                    if(this.employee.epas == this.empData[i].epas){
                        alert("登录成功");
                        this.$router.push('/emp');
                        break;
                    }
                    else{
                        alert("密码错误");
                        // this.$router.push('/login');
                        // this.$router.go('/login');
                        break;
                    }
                }
            }
            if (res == false)
                alert("没有此员工");
        },
        log2(){
            this.$router.push('/log2');
        }
    },mounted(){
        axios.get('/TbEmployeeSelectAll').then((result) => {
            this.empData=result.data.data;
            console.log(JSON.stringify(this.empData));
        });
    }
}
</script>



<style>
    .el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
  }
</style>

